package Figures;

import java.awt.*;
import java.awt.geom.Ellipse2D;
import java.io.Serializable;

/**
 * 类功能描述：
 *圆类，用了Ellipsed2D对象来进行绘制
 * @author lix
 * @date 2024/01/02
 */

public class Oval extends ClosedGraphics implements Serializable {
    private Ellipse2D ellipse2D;

    public Oval(Point start, Point end, int size, Color color) {
        super(start, end, size, color);
        ellipse2D = new Ellipse2D.Double(point_left_top.x, point_left_top.y, width, height);
    }

    @Override
    public void fill(Graphics2D g) {
        g.setColor(getFillColor());
        g.fill(ellipse2D);
    }

    @Override
    public void Draw(Graphics2D g) {
        g.setColor(ShapeColor);
        g.setStroke(new BasicStroke(size));
        g.draw(ellipse2D);
        if (fillColor != null) {
            g.setColor(fillColor);
            g.fill(ellipse2D);
        }
        if (isSelected) showSelectBorder(g);
    }

    @Override
    public void setEnd(Point end) {
        super.setEnd(end);
        //计算左上角和右下角和高度
        calcPoint_left_top();
        calcPoint_right_bottom();
        calcWidthAndHeight();
        ellipse2D.setFrame(point_left_top.x, point_left_top.y, width, height);
        point_center = new Point(((point_left_top.x + point_right_bottom.x) / 2), (point_left_top.y + point_right_bottom.y) / 2);
    }

    @Override
    public void Move(Point destination) {
        super.Move(destination);
        ellipse2D.setFrame(point_left_top.x, point_left_top.y, width, height);
    }
}
